package algorithm.leetcode.I1to100;

/**
 * 思路: 把后面的数字赋值到重复的位置上
 */


public class Q26 {

    public int removeDuplicates(int[] nums) {
        int lastIndex = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[lastIndex]) {
                nums[++lastIndex] = nums[i];
            }
        }
        return lastIndex+1;
    }

    public static void main(String[] args) {
        Q26 q26 = new Q26();
        System.out.println(q26.removeDuplicates(new int[]{1, 1, 2, 3, 3, 4, 4}));
        System.out.println(q26.removeDuplicates(new int[]{}));
    }
}
